<template>
  <div>
    <!-- 地址编辑 -->
    <van-address-edit
      :area-list="areaList"
      show-postal
      show-delete
      show-set-default
      show-search-result
      :search-result="searchResult"
      :area-columns-placeholder="columnsPlaceholder"
      @save="onSave"
      @delete="onDelete"
    />
  </div>
</template>
<script>
// 获取省份以及县区选择
import SelectProvince from '../../assets/js/selectProvince.js'
import { mapState, mapMutations } from 'vuex'
export default {
  data() {
    return {
      addlistq: '',
      save: {},
      // detail: '',
      // 地区列表对象
      areaList: SelectProvince,
      // 详细地址搜索结果
      searchResult: [],
      //  地区选择列占位提示文字
      columnsPlaceholder: ['请选择', '请选择', '请选择']
    }
  },
  created() {
    this.getlist()
  },
  // localStorage.setItem("todo", JSON.stringify(todolist));
  //     var data = localStorage.getItem("todo");
  methods: {
    ...mapMutations(['AdTheAddress', 'addlistk']),
    getlist() {
      this.addlistk()
    },
    // 保存触发
    onSave(val) {
      // console.log(cal)

      console.log(this.shuID)

      this.addlistq =
        val.province + val.city + val.county + val.addressDetail + ' '

      const addlists = {
        id: this.shuID,
        name: val.name,
        tel: val.tel,
        address: this.addlistq,
        isDefault: val.isDefault
      }
      // alert(11)
      // localStorage.setItem('list', JSON.stringify(addlists))
      this.AdTheAddress(addlists)
      this.$router.push('/addresslist')
    },
    // 删除触发
    onDelete() {
      this.save = {}
    }
  },
  computed: {
    ...mapState(['shuID'])
  }
}
</script>
<style lang="less" scoped>
</style>